package com.zhy.generator.commons.response;

import com.google.common.collect.Lists;

/**
 * 返回结果
 *
 * @author 粽子
 */
public class ResultUtil {
    /**
     * 返回结果
     *
     * @param errcode
     * @param msg
     * @param data
     * @return
     */
    public static ResultResponse jsonMsg(int errcode, String msg, Object data) {
        ResultResponse resultDO = new ResultResponse();
        resultDO.setErrcode(errcode);
        resultDO.setMsg(msg);
        if (null == data) {
            data = Lists.newArrayList();
        }
        resultDO.setData(data);
        return resultDO;
    }

    /**
     * 返回操作结果
     *
     * @param resultErrCodeEnum
     * @return
     */
    public static ResultResponse jsonMsg(ResultErrCodeEnum resultErrCodeEnum) {
        ResultResponse resultDO = new ResultResponse();
        resultDO.setErrcode(resultErrCodeEnum.getStatus());
        resultDO.setMsg(resultErrCodeEnum.getStatusDesc());
        resultDO.setData(Lists.newArrayList());
        return resultDO;
    }

    /**
     * 返回结果
     *
     * @param resultErrCodeEnum
     * @param data
     * @return
     */
    public static ResultResponse jsonMsg(ResultErrCodeEnum resultErrCodeEnum, Object data) {
        ResultResponse resultDO = new ResultResponse();
        resultDO.setErrcode(resultErrCodeEnum.getStatus());
        resultDO.setMsg(resultErrCodeEnum.getStatusDesc());
        if (null == data) {
            data = Lists.newArrayList();
            resultDO.setMsg("暂未设置数据");
        }
        resultDO.setData(data);
        return resultDO;
    }


    /**
     * 返回结果带分页
     *
     * @param errcode
     * @param msg
     * @param data
     * @return
     */
    public static ResultResponse jsonPagerMsg(int errcode, String msg, Object data, Long count, Integer p, Integer prow) {
        ResultResponse resultDO = new ResultResponse();
        resultDO.setErrcode(errcode);
        resultDO.setMsg(msg);
        if (null == data) {
            data = Lists.newArrayList();
        }
        resultDO.setData(data);
        resultDO.setTotal(count);
        resultDO.setPageIndex(p);
        resultDO.setPageSize(prow);
        return resultDO;
    }
}
